package com.my.junit.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.my.junit.domain.User;
import com.my.junit.mapper.UserMapper;
import com.my.junit.service.BarService;
import com.my.junit.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Random;
import java.util.UUID;

/**
 * @author Zijian Liao
 * @since 1.0.0
 */
@Service
public class FooServiceImpl implements FooService {

    @Autowired
    private BarService barService;

    @Override
    public String hello() {
        System.out.println("foo hello");
        return "foo hello";
    }

    @Override
    public String mock() {
        System.out.println("foo mock");
        return barService.mock();
    }

    @Override
    public String mock(int a) {
        return barService.mock(a);
    }

    @Override
    public String partMock() {
        barService.hello();
        barService.real();
        return barService.mock();
    }

    @Autowired
    private UserMapper userMapper;

    @Override
    public User selectUser(String name) {
        // 假设这里的user是从数据库查出
//        return new User(1L, "张三");
        LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(User::getName, name);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public boolean insertUser(User user) {
        return true;
    }

    @Override
    public String powermock() {
        return JSON.toJSONString(new User("张三"));
    }

    @Value("${abc}")
    private String abc;
}
